require 'social_share_link/providers'

module SocialShareLink
  module ViewHelpers
    def social_share(provider, options = {}, &block)
      raise I18n.t(:unknown_provider, scope: :social_share) unless PROVIDERS.include?(provider)

      options = options.with_indifferent_access

      classes = (options[:class] || "").split
      classes << "social-share-link"
      classes << provider.to_s
      options[:class] = classes.join(" ")

      data = (options[:data] || {}).with_indifferent_access
      data[:media] = provider.to_s
      data[:title] = options.delete(:title) || ""
      data[:text] = options.delete(:text) || ""
      data[:url] = options.delete(:url) ||  ""
      options[:data] = data

      options[:href] ||= "#"
      options[:title] = I18n.t(provider, scope: :social_share, default: "Share on #{provider.to_s}")

      content_tag(:a, nil, options, &block)
    end
  end
end
